package com.curso.constants;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Utilities {
	private static Pattern pattern;
	private static Matcher matcher;

	private static final String PASSWORD_PATTERN = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!\"@#$%&()=?]).{8,20})";
	private static final String USER_PATTERN = "^[A-Za-z0-9@#_-]{3,15}$";

	/**
	 * Validate password with regular expression
	 * 
	 * @param password(?=.*[!\"@#$%&()=?])
	 *            password for validation
	 * @return true valid password, false invalid password
	 */
	public static boolean isValidPassword(final String password) {
		pattern = Pattern.compile(PASSWORD_PATTERN);
		matcher = pattern.matcher(password);
		return matcher.matches();
	}

	public static boolean isValidUserName(final String userName) {
		pattern = Pattern.compile(USER_PATTERN);
		matcher = pattern.matcher(userName);
		return matcher.matches();
	}

	public static boolean isValidEmail(String email) {
		return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
	}
}
